/**
 * Copyright &copy; com.smooth.common
 */
package com.smooth.site.sx.mag.biz.gen.service;

import java.util.List;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang3.StringUtils;

import com.smooth.common.site.common.PageDb;
import com.smooth.common.site.common.enums.DelFlagEnums;
import com.smooth.common.site.common.persistence.Page;
import com.smooth.common.site.common.utils.IdGenerater;
import com.smooth.dao.gen.BizGentestMapper;
import com.smooth.dao.gen.bean.BizGentest;
import com.smooth.dao.gen.bean.BizGentestExample;

/**
 * gentestService
 * @author 北冥
 * @version 2018-12-11
 */
@Service
@Transactional(readOnly = true)
public class BizGentestService{

	@Autowired
	BizGentestMapper bizGentestMapper;
	@Autowired
	IdGenerater idGenerater;
	
	public BizGentest get(String no) {
		return bizGentestMapper.selectByPrimaryKey(no);
	}
	
	public List<BizGentest> findList(BizGentest bizGentest) {
		BizGentestExample bizGentestExample = new BizGentestExample();
		BizGentestExample.Criteria criteria = bizGentestExample.createCriteria();
		
		return bizGentestMapper.selectByExample(bizGentestExample);
	}
	
	public Page<BizGentest> findPage(Page<BizGentest> page, BizGentest bizGentest) {
		BizGentestExample bizGentestExample = new BizGentestExample();
		BizGentestExample.Criteria criteria = bizGentestExample.createCriteria();
		
		List<BizGentest> dlist = bizGentestMapper.selectByExample(bizGentestExample);
		page.setList(dlist);
		page.setCount(bizGentestMapper.countByExample(bizGentestExample));
		
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(BizGentest bizGentest) {
		if(StringUtils.isNotEmpty(bizGentest.getId())&&get(bizGentest.getId())!=null) {
			bizGentestMapper.updateByPrimaryKeySelective(bizGentest);
		}else {
			Date date = new Date();
			bizGentest.setCreateDate(date);
			bizGentest.setDelFlag(DelFlagEnums.DEL_FLAG_NORMAL.value);
			bizGentest.setId(idGenerater.genClsNo("bizGentest"));
			bizGentest.setUpdateDate(date);
			bizGentestMapper.insertSelective(bizGentest);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(BizGentest bizGentest) {
		bizGentestMapper.deleteByPrimaryKey(bizGentest.getId());
	}
	
}